
var target = UIATarget.localTarget();

var loop = true; // true sets infinite loop count
var loopCounter = 0; 
var tabBar = UIATarget.localTarget().frontMostApp().mainWindow().tabBar();




while(loop)
{

//general 

UIALogger.logMessage("SCRIPT RUN : " + loopCounter);

//MultiTask Check
UIALogger.logStart("++++++++++++++++++++ Multitask Testing ++++++++++++++++++++");
UIALogger.logMessage("Starting multitask testing..");
target.deactivateAppForDuration(5);
UIALogger.logPass("Multitasking confirmed");

	
//Buttons link Check
UIALogger.logStart("++++++++++++++++++++ Buttons link Testing ++++++++++++++++++++");
		var selected1 = tabBar.buttons()[1];
		selected1.tap();
		UIATarget.localTarget().delay(1);
		UIALogger.logStart("Initial node tree for tab 1");
		target.logElementTree();
		

		var selected2 = tabBar.buttons()[2];
		selected2.tap();
		UIATarget.localTarget().delay(1);
		UIALogger.logStart("Initial node tree for tab 2");
		target.logElementTree();
		

		var selected3 = tabBar.buttons()[3];
		selected1.tap();
		UIATarget.localTarget().delay(1);
		UIALogger.logStart("Initial node tree for tab 3");
		target.logElementTree();
		UIALogger.logPass();
UIATarget.localTarget().delay(1);
target.frontMostApp().mainWindow().tabBar().buttons()["News"].tap();
	
//Check button bashing
UIALogger.logStart("++++++++++++++++++++ Destruction Testing ++++++++++++++++++++");
target.frontMostApp().mainWindow().scrollViews()[0].buttons()["UK NEWS"].tap();
target.frontMostApp().mainWindow().scrollViews()[0].buttons()["TOP STORIES"].tap();
target.frontMostApp().mainWindow().scrollViews()[0].buttons()["UK NEWS"].doubleTap();
target.frontMostApp().mainWindow().scrollViews()[0].buttons()["TOP STORIES"].tap();
target.frontMostApp().mainWindow().scrollViews()[0].buttons()["UK NEWS"].doubleTap();
target.frontMostApp().mainWindow().scrollViews()[0].buttons()["TOP STORIES"].tap();
target.frontMostApp().mainWindow().scrollViews()[0].buttons()["UK NEWS"].doubleTap();
target.frontMostApp().mainWindow().scrollViews()[0].buttons()["TOP STORIES"].tap();
target.frontMostApp().mainWindow().scrollViews()[0].buttons()["UK NEWS"].doubleTap();
target.frontMostApp().mainWindow().scrollViews()[0].buttons()["TOP STORIES"].tap();
target.frontMostApp().mainWindow().scrollViews()[0].buttons()["UK NEWS"].doubleTap();
target.frontMostApp().mainWindow().scrollViews()[0].buttons()["TOP STORIES"].tap();
target.frontMostApp().mainWindow().scrollViews()[0].buttons()["UK NEWS"].doubleTap();
target.frontMostApp().mainWindow().scrollViews()[0].buttons()["TOP STORIES"].tap();
target.frontMostApp().mainWindow().scrollViews()[0].buttons()["UK NEWS"].doubleTap();
target.frontMostApp().mainWindow().scrollViews()[0].buttons()["TOP STORIES"].tap();
target.frontMostApp().mainWindow().scrollViews()[0].buttons()["UK NEWS"].doubleTap();
target.frontMostApp().mainWindow().scrollViews()[0].buttons()["TOP STORIES"].tap();
target.frontMostApp().mainWindow().scrollViews()[0].buttons()["UK NEWS"].tap();
UIALogger.logPass("Destruction testing complete"); 
//Check Scrolling
	UIALogger.logStart("++++++++++++++++++++ Scroll Testing ++++++++++++++++++++");
target.frontMostApp().mainWindow().tableViews()["Empty list"].cells()[8].tap();
target.frontMostApp().mainWindow().navigationBar().leftButton().tap();
target.frontMostApp().mainWindow().tableViews()["Empty list"].cells()[5].scrollToVisible();
target.frontMostApp().mainWindow().tableViews()["Empty list"].cells()[3].staticTexts()[0].scrollToVisible();
target.frontMostApp().mainWindow().tableViews()["Empty list"].cells()[1].tap();
target.frontMostApp().mainWindow().navigationBar().leftButton().tap();
	UIALogger.logPass("Scroll testing complete");
//Check Ability to select menu items
	UIALogger.logStart("++++++++++++++++++++ Button Testing ++++++++++++++++++++");
target.frontMostApp().mainWindow().tabBar().buttons()["Video"].tap();
target.frontMostApp().mainWindow().tableViews()[0].cells()[0].tap();

	
	UIALogger.logStart("++++++++++++++++++++ Finished button Testing ++++++++++++++++++++");
//Check page transitions work

//Check App exit and hanging 

//Performance testing
	
//Safari Check
//Starts a short journey to find a link and press it
UIATarget.localTarget().delay(1);
target.frontMostApp().mainWindow().navigationBar().leftButton().tap();
	
	
target.frontMostApp().mainWindow().tabBar().buttons()["Discuss"].tap();
target.frontMostApp().mainWindow().tableViews()["Empty list"].cells()["Blogs, In-depth analysis and a personal view - from our team of experts"].tap();
target.frontMostApp().mainWindow().toolbar().buttons()["browser share active"].tap();
//target.frontMostApp().actionSheet().buttons()["Launch Browser"].tap();
target.deactivateAppForDuration(1);
target.frontMostApp().actionSheet().buttons()["Close"].tap();
target.frontMostApp().mainWindow().navigationBar().leftButton().tap();
target.frontMostApp().mainWindow().tabBar().buttons()["News"].tap();
	
	++loopCounter;
}